package com.css.zfzx.sjcj.common.utils;

import com.css.bpm.platform.api.local.PlatformAPI;
import com.css.bpm.platform.org.role.repository.entity.RoleEntity;
import com.css.bpm.platform.utils.PlatformSessionUtils;

import java.util.List;

public class ServerUtil {

    //终极质检员
    static String ultimateQC = "ultimate";
    //普通质检员
    static String ordinaryQc = "ordinary";

    /**
     * 判断某用户是否存在角色
     *
     * @param roleEntities
     * @param code
     * @return
     */
    public static boolean isContaintRole(List<RoleEntity> roleEntities, String code) {
        boolean flag = false;
        for (RoleEntity role : roleEntities) {
            if (code.equals(role.getRoleCode())) {
                flag = true;
                break;
            }
        }
        if (flag) {
            return true;
        } else {
            return false;
        }
    }

    /**
     *  判断当前用户是否是终极质检员
     *
     * @return 是否终检员
     */
    public static boolean isUltimateQc(){
        String userId = PlatformSessionUtils.getUserId();
        if(null == userId){
            return false;
        }
        List<RoleEntity> roles = PlatformAPI.getOrgAPI().getUserAPI().getRoles(userId);

        return isContaintRole(roles,ServerUtil.ultimateQC);
    }

    public static String getQcFieldString(){
        return isUltimateQc() ? "3" : "2";
    }
}
